﻿using PorterStemmerAlgorithm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Utils
{
    public class Document
    {
        public Document(string title, string content)
        {
            _title = title;
            _content = content;
            foreach (string s in title.Split(' '))
            {
                _titleStemmed += Stemmer.stemTerm(Regex.Replace(s.Replace("\n", String.Empty).ToLower(), @"[^\w\s]", "")) + " "; 
            }
            _titleStemmed = _titleStemmed.Substring(0, _titleStemmed.Length - 1);
            foreach (string s in content.Split(' '))
            {
                _contentStemmed += Stemmer.stemTerm(Regex.Replace(s.Replace("\n", String.Empty).ToLower(), @"[^\w\s]", "")) + " ";
            }
            _contentStemmed = _contentStemmed.Substring(0, _contentStemmed.Length - 1);
            //_titleStemmed = Stemmer.stemTerm(Regex.Replace(_title.Replace("\n", String.Empty).ToLower(), @"[^\w\s]", "")).Replace("\n", String.Empty);
            //_contentStemmed = Stemmer.stemTerm(Regex.Replace(_content.Replace("\n", String.Empty).ToLower(), @"[^\w\s]", ""));
        }

        private string _title { get; set; }

        public string Title
        {
            get
            {
                return _title;
            }
        }

        private string _content { get; set; }

        public string Content 
        {
            get
            {
                return _content;
            }
        }

        private string _titleStemmed { get; set; }

        public string TitleStemmed
        {
            get
            {
                return _titleStemmed;
            }
        }

        private string _contentStemmed { get; set; }

        public string ContentStemmed
        {
            get
            {
                return _contentStemmed;
            }
        }

        private int _id { get; set; }

        public int Id
        {
            get
            {
                return _id;
            }
            set
            {
                _id = value;
            }
        }

        private Double _score { get; set; }

        public Double Score
        {
            get
            {
                return _score;
            }
            set
            {
                _score = value;
            }
        }

        private IStemmerInterface _stemmer { get; set; }
        private IStemmerInterface Stemmer
        {
            get
            {
                if (_stemmer == null)
                    _stemmer = new PorterStemmer();
                return _stemmer;
            }
        }

        public override string ToString()
        {
            return Title + " " + Content;
        }
    }
}
